<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search results (${fn:length(searchResults)})</title>
</head>
<body>

Search results:
<br><br>
<table>
	<thead>
		<tr>
			<td>Title</td>
			<sec:authorize access="isAuthenticated()">
			<td>Text abstract</td>
			<td>MLT</td>
			</sec:authorize>
		</tr>
	</thead>
	<tbody>
		<c:if test="${ empty searchResults }">
			<tr><td colspan="2">-- no results found --</td></tr>
			<c:if test="${ empty suggestions }">
				-- no suggestions --
			</c:if>
			<c:if test="${ not empty suggestions }">
				Did you mean:<br>
				<c:forEach var="currentSuggestion" items="${ suggestions }">
					<a href="${pageContext.request.contextPath}/search/did-you-mean">${ currentSuggestion.value }</a>
					<br>
				</c:forEach>
			</c:if>
		</c:if>
		<c:if test="${ not empty searchResults }">
			<c:forEach var="currentResult" items="${searchResults}">
				<tr>
					<td><a href="${pageContext.request.contextPath}/adverts/view/${currentResult.advertId}">${currentResult.title}</a></td>
					<sec:authorize access="isAuthenticated()">
					<td>${currentResult.highlight}</td>
					<td><a href="${pageContext.request.contextPath}/search/more-like-this/${ currentResult.documentId }">More like this</a></td>
					</sec:authorize>
				</tr>
			</c:forEach>
		</c:if>
	</tbody>
</table>

</body>
</html>